package com.yyge.util;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTPayload;
import cn.hutool.jwt.JWTUtil;

import java.util.HashMap;
import java.util.Map;

public class JwtUtile {
    public static String getToken(String userName,String PassWord){
        DateTime now = DateTime.now();
		DateTime newTime = now.offsetNew(DateField.MINUTE, 1);

		Map<String,Object> payload = new HashMap<String,Object>();
		//签发时间
		payload.put(JWTPayload.ISSUED_AT, now);
		//过期时间
		payload.put(JWTPayload.EXPIRES_AT, newTime);
		//生效时间
		payload.put(JWTPayload.NOT_BEFORE, now);
		//载荷
		payload.put("userName", userName);
		payload.put("passWord", PassWord);

		String key = "123456789";
		String token = JWTUtil.createToken(payload, key.getBytes());
		System.out.println(token);
        return token;
    }

	public static boolean tokenVerify(String token){
		String key = "123456789";
		JWT jwt = JWTUtil.parseToken(token);

		boolean verifyKey = jwt.setKey(key.getBytes()).verify();

		boolean verifyTime = jwt.validate(0);
		return verifyTime;
	}
}
